from collections import deque
from typing import List


class AC:

    def __init__(self, words: List[str]):
        self.n = n = len(words)
        self.total = total = sum(len(word) for word in words) + 1

        self.trie = [[0] * 26 for _ in range(total)]
        self.end = [0] * n
        self.fail = [0] * total
        self.inverse_fail_tree = [[] for _ in range(total)]
        self.cnt = 0
        self.build(words)

    def build(self, words: List[str]):
        for i, word in enumerate(words):
            self._insert(i, word)
        self._set_fail()
        self._build_inverse_fail_tree()

    def _insert(self, i, word: str):
        trie = self.trie
        cur = 0

        for char in word:
            path = ord(char) - ord('a')
            if not trie[cur][path]:
                self.cnt += 1
                trie[cur][path] = self.cnt
            cur = trie[cur][path]
        self.end[i] = cur  # 每个单词结尾的节点的编号

    def _set_fail(self):
        trie, fail = self.trie, self.fail
        q = deque([v for v in trie[0] if v])
        while q:
            for _ in range(len(q)):
                u = q.popleft()
                for v in range(26):
                    if trie[u][v]:
                        q.append(trie[u][v])
                        fail[trie[u][v]] = trie[fail[u]][v]
                    else:
                        trie[u][v] = trie[fail[u]][v]

    def _build_inverse_fail_tree(self):
        inverse_fail_tree, fail = self.inverse_fail_tree, self.fail
        for u, v in enumerate(fail):
            inverse_fail_tree[v].append(u)  # 反向建fail树
        inverse_fail_tree[0].remove(0)

    def match(self, article: str) -> List[int]:
        n, total, trie, inverse_fail_tree, end = self.n, self.total, self.trie, self.inverse_fail_tree, self.end
        times = [0] * total

        u = 0
        for c in article:
            v = trie[u][ord(c) - ord('a')]
            times[v] += 1
            u = v
        def dfs2(u):
            stack = [u]
            visited = [False] * total
            while stack:
                u = stack[-1]
                if not visited[u]:
                    visited[u] = True
                    for v in inverse_fail_tree[u]:
                        stack.append(v)
                else:
                    stack.pop()
                    time = times[u]
                    for v in inverse_fail_tree[u]:
                        time += times[v]
                    times[u] = time

        dfs2(0)
        res = [0] * n
        for i, node in enumerate(end):
            res[i] = times[node]
        return res

import sys

lines = sys.stdin.readlines()
n = int(lines[0])
words = [v.strip() for v in lines[1:-1]]
article = lines[-1].strip()
ac = AC(words)
ans = ac.match(article)
output = '\n'.join(map(str, ans))
sys.stdout.write(output)
